home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 436_01 / inutil.c < prev    next >
Text File  |  1994-10-07  |  6KB  |  195 lines

  1. /*************************************************************************
  2.     Source file:  INUTIL.C
  3.  
  4.     INCON utility routines.  All routines in this module are public,
  5.     and may be called directly by programs that link INCON.LIB.
  6.  
  7.     Compiler:  Borland Turbo C 2.01
  8.  
  9.     INCON source files and the object and library files created from
  10.     them are:
  11.         Copyright (c) 1993-94, Richard Zigler.
  12.     You may freely distribute unmodified source, object, and library
  13.     files, and incorporate them into your own non-commercial software,
  14.     provided that this paragraph and the program name and copyright
  15.     strings defined in INCON.C are included in all copies.
  16. *************************************************************************/
  17.  
  18. #include <dos.h>                                /* geninterrupt()                        */
  19. #include "indefs.h"                            /* globals and definitions            */
  20. #include "indecl.h"                            /* public utility routines            */
  21.  
  22. /************************************************************************/
  23. /* Cursor handling.  Call with OFF argument prior to ON, and with            */
  24. /* SAVE prior to RESTORE.                                                                */
  25.  
  26. void pascal Cursor( short CurSwitch )
  27.     {
  28.  
  29.     switch ( CurSwitch )
  30.         {
  31.         static short cshape, cpos;            /* cursor shape, position            */
  32.  
  33.         case OFF:                                /* turn off the cursor                */
  34.             _AH = CUR_GET;                        /* get cursor shape/position        */
  35.             _BH = ACT_PAGE;                    /* on video page 0                    */
  36.             geninterrupt( BIOS_VIDEO );
  37.             cshape = _CX;                        /* save shape                            */
  38.             _AH =  CUR_SIZE;
  39.             _CX |= CUR_OFF;                    /* set bit 5 in CH                    */
  40.             geninterrupt( BIOS_VIDEO );
  41.             break;
  42.  
  43.         case ON:                                    /* turn cursor back on                */
  44.             _AH = CUR_SIZE;
  45.             _CX = cshape & ~CUR_OFF;        /* clear bit 5 in CH                    */
  46.             geninterrupt( BIOS_VIDEO );
  47.             break;
  48.  
  49.         case SAVE:                                /* save cursor position                */
  50.             _AH = CUR_GET;
  51.             _BH = ACT_PAGE;
  52.             geninterrupt( BIOS_VIDEO );
  53.             cpos = _DX;
  54.             break;
  55.  
  56.         case RESTORE:                            /* restore cursor position            */
  57.             _AH = CUR_SET;
  58.             _BH = ACT_PAGE;
  59.             _DX = cpos;
  60.             geninterrupt( BIOS_VIDEO );
  61.             break;
  62.  
  63.         default:
  64.             break;
  65.  
  66.         }
  67.     }                                                /**** Cursor()                        ****/
  68.  
  69. /************************************************************************/
  70. /*    GetCursor()                                                                                */
  71. /*    Get absolute screen coordinates.                                                    */
  72.  
  73. void pascal GetCursor( short * Row, short * Col )
  74.     {
  75.  
  76.     _AH = CUR_GET;
  77.     _BH = 0;
  78.     geninterrupt( BIOS_VIDEO );
  79.     *Row = _DH;
  80.     *Col = _DL;
  81.     }
  82.  
  83. /************************************************************************/
  84. /*    GetVideoAttr()                                                                            */
  85. /*    Get video attribute at cursor on current page.                                */
  86.  
  87. int pascal GetVideoAttr( void )
  88.     {
  89.  
  90.     _AH = GET_ATTR;
  91.     _BH = 0;
  92.     geninterrupt( BIOS_VIDEO );
  93.     return ( _AH );
  94.     }
  95.  
  96. /************************************************************************/
  97. /*    PutCursor()                                                                                */
  98. /*    Place cursor at row and col on video page 0.                                    */
  99.  
  100. void pascal PutCursor( short Row, short Col )
  101.     {
  102.  
  103.     _AH = CUR_SET;
  104.     _BH = 0;
  105.     _DH = Row;
  106.     _DL = Col;
  107.     geninterrupt( BIOS_VIDEO );
  108.     }
  109.  
  110. /************************************************************************/
  111. /*    WordLeft()                                                                                */
  112. /*    Scan string left from current position to first occurence of            */
  113. /* search character.  Return index to character following search            */
  114. /* character.                                                                                */
  115.  
  116. int pascal WordLeft
  117.     (
  118.     register int    Pos,                        /* current index                        */
  119.     char far            *String,                    /* string to scan                        */
  120.     char                SearchChar                /* search character                    */
  121.     )
  122.     {
  123.  
  124.     /****
  125.         Scan left while the previous character is the search
  126.         character.  The prefix-decrement of Pos is necessary
  127.         to obtain the previous character.  If the cursor is
  128.         within a word, the test for SearchChar fails immedi-
  129.         ately; if it is at the beginning or between words,
  130.         the test fails at the end of the previous word.
  131.     ****/
  132.  
  133.     while ( Pos >= 0 && String[--Pos] == SearchChar )
  134.         ;
  135.  
  136.     /****
  137.         Continue to scan left while the previous character is not
  138.         the search character.  In the first case noted above, the
  139.         test fails at the beginning of the word; in the second it
  140.         fails at the beginning of the previous word.
  141.     ****/
  142.  
  143.     while ( Pos >= 0 && String[--Pos] != SearchChar )
  144.         ;
  145.  
  146.     /****
  147.         The prefix-decrement of Pos leaves it pointing at the
  148.         character previous to the target, so it is incremented
  149.         before being returned.
  150.     ****/
  151.  
  152.     return( ++Pos );
  153.     }
  154.  
  155. /************************************************************************/
  156. /*    WordRight()                                                                                */
  157. /*    This operation is the mirror image of WordLeft(); the scan is            */
  158. /*    bounded by the end-of-string null byte.                                        */
  159.  
  160. int pascal WordRight
  161.     (
  162.     register int    Pos,                        /* current index                        */
  163.     char far            *String,                    /* string to scan                        */
  164.     char                SearchChar                /* search character                    */
  165.     )
  166.     {
  167.  
  168.     while ( String[Pos] && String[++Pos] != SearchChar ) ;
  169.     while ( String[Pos] && String[++Pos] == SearchChar ) ;
  170.     return( Pos );
  171.     }
  172.  
  173. /************************************************************************/
  174. /*    WriteMany()                                                                                */
  175. /*    Writes character and attribute combination at current cursor            */
  176. /*    position; repeats Num times.  The cursor is not moved.                    */
  177.  
  178. void pascal WriteMany
  179.     (
  180.     BYTE                Chr,                        /* ASCII character                    */
  181.     int                Attr,                        /* video attribute                    */
  182.     int                Num                        /* times to write Attr/ch            */
  183.     )
  184.     {
  185.  
  186.     _AH = WRITE_MANY;
  187.     _AL = Chr;
  188.     _BH = 0;
  189.     _BL = (BYTE) Attr;
  190.     _CX = Num;
  191.     geninterrupt( BIOS_VIDEO );
  192.     }
  193.  
  194. /**** EOF:  INUTIL.C ****/
  195.